package com.zzsy.shoppingpro.home.acitivty;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.app.Config;
import com.zzsy.shoppingpro.base.BaseActivity;
import com.zzsy.shoppingpro.commentactivity.GoodsInfoActivity;
import com.zzsy.shoppingpro.home.adapter.RecommendDeticGridViewAdapter;
import com.zzsy.shoppingpro.home.bean.GoodsBean;
import com.zzsy.shoppingpro.home.bean.HomeBean;


import java.util.ArrayList;
import java.util.List;

public class RecommendDeticActivity extends BaseActivity {
private List<HomeBean.ResultBean.RecommendInfoBean> recommend_info;
    private GridView gvRecommends;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_detic);
        recommend_info = new ArrayList<>();
        initData();
        initUI();
    }

    /**
     * 初始化控件
     * */
    private void initUI() {
        TextView tvXin = findViewById(R.id.title);
        tvXin.setText("新品列表");
        gvRecommends = findViewById(R.id.gv_recommends);
        RecommendDeticGridViewAdapter recommendDeticGridViewAdapter = new RecommendDeticGridViewAdapter(RecommendDeticActivity.this,recommend_info);
        gvRecommends.setAdapter(recommendDeticGridViewAdapter);
        gvRecommends.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String cover_price = recommend_info.get(position).getCover_price();
                String name = recommend_info.get(position).getName();
                String figure = recommend_info.get(position).getFigure();
                String product_id = recommend_info.get(position).getProduct_id();
                GoodsBean goodsBean = new GoodsBean(name, cover_price, figure, product_id);

                Intent intent = new Intent(RecommendDeticActivity.this, GoodsInfoActivity.class);
                intent.putExtra(Config.GOODS_BEAN, goodsBean);
                startActivity(intent);
            }
        });
    }

    /**
     * 初始化数据
     * */
    private void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        recommend_info = (ArrayList<HomeBean.ResultBean.RecommendInfoBean>) bundle.getSerializable("recommend");

    }
}
